package com.study.common.security;

import com.study.common.utils.SafetyUtils;
import org.apache.shiro.authc.AuthenticationInfo;
import org.apache.shiro.authc.AuthenticationToken;
import org.apache.shiro.authc.UsernamePasswordToken;
import org.apache.shiro.authc.credential.SimpleCredentialsMatcher;

import java.io.UnsupportedEncodingException;
import java.security.NoSuchAlgorithmException;

public class PasswordPermission extends SimpleCredentialsMatcher {
    @Override
    public boolean doCredentialsMatch(AuthenticationToken token, AuthenticationInfo info) {
            //       获取传入的token
            UsernamePasswordToken userToken = (UsernamePasswordToken) token;
            // 将密码转换为string类型
            String password = String.valueOf(userToken.getPassword());
            //        加密后的密码
            Object encryptionPassword = password;
            Object accountCredentials = getCredentials(info);
            // 判断数据库中的密码和加密过后的密码是否相等
            return equals(encryptionPassword, accountCredentials);
    }
}